<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite/customcomponents"
	   xmlns:c="http://java.sun.com/jsp/jstl/core"
	contentType="text/html">
	
	<h:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title><h:outputText value="#{label['exampleBeanCRUD.title']} - #{label['appNameTitle']}"/></title>
	</h:head>	
	<h:body>
		<cc:LatamHeader userInfo="true">
			<cc:AppHeaderMenu/>
		</cc:LatamHeader>
			
		<p:growl id="growl" showDetail="false" sticky="false" severity="info"/>
	   <p:messages id="messages" showDetail="false" autoUpdate="true" closable="true" />
		 
		<h:form id="listForm">
			<p:panel styleClass="latam_body_panel">
				<p:dataTable  id="listOfExampleBean" scrollable="true" scrollWidth="97%" 
					rows="10" 
					paginator="true"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="5,10,15"    
					var="bean" value="#{profesionalBeanCrudMB.list}"
					editable="true">	
					<f:facet name="header">#{label['title.identificacion.beneficiario']}</f:facet>
					
					<p:column width="100" headerText="#{label['label.id']}" > 
						<h:outputText value="#{bean.id}"/>
					</p:column>
					<p:column filterBy="#{bean.rut}"  width="100" headerText="#{label['profesional.rut']}" >
						<h:outputText value="#{bean.rut}"/>
					</p:column>
					<p:column width="100" headerText="#{label['profesional.nombres']}" >
						<h:outputText value="#{bean.nombre}"/>
					</p:column>
					<p:column width="100" headerText="#{label['profesional.apellido.paterno']}" >
						<h:outputText value="#{bean.apellido}"/>
					</p:column>				
					<p:column width="100" headerText="#{label['profesional.direccion']}" >
						<h:outputText value="#{bean.direccion}"/>
					</p:column>
					<p:column width="100" headerText="#{label['profesional.telefono.celular']}" >
						<h:outputText value="#{bean.celular}"/>
					</p:column>
					<p:column width="200"  headerText="#{label['profesional.correo.electronico']}" >
						<h:outputText value="#{bean.correoElectronico}"/>
					</p:column>
					
					<p:column width="100"  headerText="#{label['label.codigo.especialidad']}" >
						<h:outputText value="#{bean.especialidadMedica.codigo}"/>
					</p:column>
					<p:column width="100"  headerText="#{label['profesional.mandatorio']}" >

					<h:outputText value="SI" rendered="#{bean.mandatorio == '1'}" />
					<h:outputText value="NO" rendered="#{bean.mandatorio == '0'}"/>
					</p:column>

					
					<p:column   width="200"  headerText="" >
						<p:commandButton 
							title="#{label['exampleBeanCRUD.edit']}"
							icon="ui-icon-pencil" 							
							oncomplete="editItemDialogwidget.show();" 
							update=":editItemForm">
							<f:setPropertyActionListener value="#{bean}" target="#{profesionalBeanCrudMB.bean}" /> 	
							<f:setPropertyActionListener value="#{bean.especialidadMedica}" target="#{profesionalBeanCrudMB.bean.especialidadMedica}" /> 					
						</p:commandButton>
						<p:commandButton 
							title="#{label['exampleBeanCRUD.remove']}"
							icon="ui-icon-trash"
							oncomplete="removeItemDialogwidget.show();" 
							update=":removeItemForm">
							<f:setPropertyActionListener value="#{bean}" target="#{profesionalBeanCrudMB.bean}" /> 		
								<f:setPropertyActionListener value="#{bean.especialidadMedica}" target="#{profesionalBeanCrudMB.bean.especialidadMedica}" /> 						
						</p:commandButton>
					</p:column>
															
					<f:facet name="footer">
	                   	<p:commandButton value="#{label['exampleBeanCRUD.newItem']}" 
	                   		onclick="newItemDialogwidget.show();" 
	                   		icon="ui-icon-star" 
	                   		actionListener="#{profesionalBeanCrudMB.createNew}"
	                   		update=":growl"
	                   		title="#{label['exampleBeanCRUD.newItem']}"/>
	               	</f:facet>
				</p:dataTable>
			</p:panel>
		</h:form>
		
		<p:dialog 				
			id="newItemDialog" widgetVar="newItemDialogwidget" 
			resizable="false" closable="true" modal="true"
			showEffect="fade" hideEffect="drop"
			header="#{label['title.identificacion.beneficiario']}">
			<h:form id="newItemForm">
				<h:panelGrid columns="2" >		
				
					<h:outputText value="#{label['label.rut']}:"/>
					<p:inputText id="rut" value="#{profesionalBeanCrudMB.bean.rut}" required="true">
							<f:validator binding="#{RutValidator}"/> 
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="rut" showSummary="true" showDetail="false" display="both"/>
													
					<h:outputText value="#{label['label.name']}:"/>
					<p:inputText id="name" value="#{profesionalBeanCrudMB.bean.nombre}" required="true">
						
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="name" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['label.lastName']}:"/>
					<p:inputText id="lastName" value="#{profesionalBeanCrudMB.bean.apellido}" required="true">
						
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="lastName" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['label.secondLastName']}:"/>
					<p:inputText id="apellidoMaterno" value="#{profesionalBeanCrudMB.bean.apellidoMaterno}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="apellidoMaterno" showSummary="true" showDetail="false" display="both"/>
				
					<h:outputText value="#{label['profesional.direccion']}:"/>
					<p:inputText id="direccion" value="#{profesionalBeanCrudMB.bean.direccion}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="direccion" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.codigo.especialidad']}:"/>
				   <p:selectOneMenu id="codigo" value="#{profesionalBeanCrudMB.bean.especialidadMedica.codigo}">
				          <f:selectItem itemLabel="Seleccione uno" itemValue="" />
				          <f:selectItems value="#{profesionalBeanCrudMB.especialidadList}"  var="bean" itemLabel="#{bean.codigo} - #{bean.nombre}" itemValue="#{bean.codigo}" />
				      </p:selectOneMenu>
					<p:spacer width="150" height="1"/>
					<p:message for="codigo" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.mandatorio']}:"/>
					<p:selectOneButton id="mandatorio" value="#{profesionalBeanCrudMB.bean.mandatorio}" required="true">
				            <f:selectItem itemLabel="SI" itemValue="1" />
				            <f:selectItem itemLabel="NO" itemValue="0" />
				    </p:selectOneButton>
					
					<p:spacer width="150" height="1"/>
					<p:message for="mandatorio" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.telefono.celular']}:"/>
					<p:inputText id="celular" value="#{profesionalBeanCrudMB.bean.celular}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="celular" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.correo.electronico']}:"/>
					<p:inputText id="correoElectronico" value="#{profesionalBeanCrudMB.bean.correoElectronico}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="correoElectronico" showSummary="true" showDetail="false" display="both"/>
					
		
				</h:panelGrid>
				
				<p:panel style="text-align: center; border-width: 0px;">
					<p:commandButton value="#{label['exampleBeanCRUD.save']}" 
						oncomplete="handleNewExampleBeanRequest(xhr, status, args);" 
						actionListener="#{profesionalBeanCrudMB.save}" 
						update="@form :growl :listForm:listOfExampleBean" />
					<p:commandButton value="#{label['exampleBeanCRUD.cancel']}"
						onclick="newItemDialogwidget.hide(); return false;" />
				</p:panel>
			</h:form>		

			<script type="text/javascript">  
 		    	function handleNewExampleBeanRequest(xhr, status, args) {  
 		        	if(args.validationFailed) { 
 		            	jQuery('#newItemDialog').effect("shake", { times:3 }, 100);
 		        	} else {
		        		newItemDialogwidget.hide();		        
		        	}
 		    	}
 			</script>
		</p:dialog>

		<p:dialog 				
			id="editItemDialog" widgetVar="editItemDialogwidget"
			resizable="false" closable="true" modal="true"
			showEffect="fade" hideEffect="drop"			 
			header="#{label['exampleBeanCRUD.editItemDialog.header']}">
			<h:form id="editItemForm">
			
						<h:panelGrid columns="2" >		
				
					<h:outputText value="#{label['label.rut']}:"/>
					<p:inputText id="rut" value="#{profesionalBeanCrudMB.bean.rut}" required="true">
							<f:validator binding="#{RutValidator}"/> 
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="rut" showSummary="true" showDetail="false" display="both"/>
													
					<h:outputText value="#{label['label.name']}:"/>
					<p:inputText id="name" value="#{profesionalBeanCrudMB.bean.nombre}" required="true">
						
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="name" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['label.lastName']}:"/>
					<p:inputText id="lastName" value="#{profesionalBeanCrudMB.bean.apellido}" required="true">
						
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="lastName" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['label.secondLastName']}:"/>
					<p:inputText id="apellidoMaterno" value="#{profesionalBeanCrudMB.bean.apellidoMaterno}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="apellidoMaterno" showSummary="true" showDetail="false" display="both"/>
				
					<h:outputText value="#{label['profesional.direccion']}:"/>
					<p:inputText id="direccion" value="#{profesionalBeanCrudMB.bean.direccion}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="direccion" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.codigo.especialidad']}:"/>
				   <p:selectOneMenu id="codigo" value="#{profesionalBeanCrudMB.bean.especialidadMedica.codigo}">
				          <f:selectItem itemLabel="Seleccione uno" itemValue="" />
				          <f:selectItems value="#{profesionalBeanCrudMB.especialidadList}"  var="bean" itemLabel="#{bean.codigo} - #{bean.nombre}" itemValue="#{bean.codigo}" />
				      </p:selectOneMenu>
					<p:spacer width="150" height="1"/>
					<p:message for="codigo" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.mandatorio']}:"/>
					<p:selectOneButton id="mandatorio" value="#{profesionalBeanCrudMB.bean.mandatorio}" required="true">
				            <f:selectItem itemLabel="SI" itemValue="1" />
				            <f:selectItem itemLabel="NO" itemValue="0" />
				    </p:selectOneButton>
					<p:spacer width="150" height="1"/>
					<p:message for="mandatorio" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.telefono.celular']}:"/>
					<p:inputText id="celular" value="#{profesionalBeanCrudMB.bean.celular}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="celular" showSummary="true" showDetail="false" display="both"/>
					
					<h:outputText value="#{label['profesional.correo.electronico']}:"/>
					<p:inputText id="correoElectronico" value="#{profesionalBeanCrudMB.bean.correoElectronico}" required="true">
					</p:inputText>
					<p:spacer width="150" height="1"/>
					<p:message for="correoElectronico" showSummary="true" showDetail="false" display="both"/>
					
			
										
				</h:panelGrid>
	
				<p:panel style="text-align: center; border-width: 0px;">
					<p:commandButton value="#{label['pamBeanCRUD.update']}" 
						actionListener="#{profesionalBeanCrudMB.update}"
						oncomplete="handleEditExampleBeanRequest(xhr, status, args);" 
						update="@form :growl :listForm:listOfExampleBean" />
					<p:commandButton value="#{label['pamBeanCRUD.cancel']}"
						onclick="editItemDialogwidget.hide(); return false;" />
				</p:panel>
			</h:form>		
			<script type="text/javascript">  
		    	function handleEditExampleBeanRequest(xhr, status, args) {  
		        	if(args.validationFailed) {
		            	jQuery('#editItemDialog').effect("shake", { times:3 }, 100);
		        	} else {
		        		editItemDialogwidget.hide();		            
		        	}
		    	}
			</script>	
		</p:dialog>
	 	 
		<p:dialog 				
			id="removeItemDialog" widgetVar="removeItemDialogwidget"
			resizable="false" closable="true" modal="true"
			showEffect="fade" hideEffect="drop"			 
			header="#{label['exampleBeanCRUD.removeItemDialog.header']}">
			<h:form id="removeItemForm">
				<h:panelGrid columns="2" >
					<h:outputText value="#{label['label.rut']}: "/>
					<h:outputText value="#{profesionalBeanCrudMB.bean.id}"/>
					
					<h:outputText value="#{label['exampleBeanCRUD.form.name']}:"/>
					<h:outputText value="#{profesionalBeanCrudMB.bean.nombre}"/>
				</h:panelGrid>
	
				<p:panel style="text-align: center; border-width: 0px;">
					<p:commandButton value="#{label['exampleBeanCRUD.remove']}" 
						actionListener="#{profesionalBeanCrudMB.remove}"
						oncomplete="handleRemoveExampleBeanRequest(xhr, status, args);" 
						update="@form :growl :listForm:listOfExampleBean" />
					<p:commandButton value="#{label['exampleBeanCRUD.cancel']}"
						onclick="removeItemDialogwidget.hide(); return false;" />
				</p:panel>
			</h:form>		
			<script type="text/javascript">  
		    	function handleRemoveExampleBeanRequest(xhr, status, args) {  
		        	if(args.validationFailed) {
		            	jQuery('#removeItemDialog').effect("shake", { times:3 }, 100);
		        	} else {
		        		removeItemDialogwidget.hide();		            
		        	}
		    	}
			</script>	
		</p:dialog>	 
	 
		<cc:LatamFooter/>
	</h:body>
</f:view>